import dataProvider from '../../service/dataProvider'
const app = getApp()
Page({
  data: {
    detailInfo: {},
    list: dataProvider.list,
    shares: dataProvider.shares,
    share: {
      title: '不看后悔！绝对经典生活小窍门大全。',
      describle: '',
      image: ''
    }
  },
  onLoad: function (options) {
    console.log('onLoad')
    const that = this

    that.setData({
      detailInfo: that.data.list[options.id]
    });

    wx.setNavigationBarTitle({
      title: ''
    })
  },
  onShareAppMessage: function () {
    let share = this.data.shares[Math.floor(Math.random() * this.data.shares.length)];
    return {
      title: this.data.share.title,
      // desc: this.data.detailInfo.sentence,
      path: '/pages/detail/index?id=' + this.data.detailInfo.id,
      imageUrl: share.imageUrl
    }
  },
  onLike: function() {
    // 在页面中定义激励视频广告
    let videoAd = null

    // 在页面onLoad回调事件中创建激励视频广告实例
    if (wx.createRewardedVideoAd) {
      videoAd = wx.createRewardedVideoAd({
        adUnitId: 'adunit-761de4367070287d'
      })
    }

    // 用户触发广告后，显示激励视频广告
    if (videoAd) {
      videoAd.show().catch(() => {
        // 失败重试
        videoAd.load()
          .then(() => videoAd.show())
          .catch(err => {
            console.log('激励视频 广告显示失败')
          })
      })
    }
  }
})

